package cn.sczhyt.modules.sys.controller;

import java.util.Arrays;

import cn.sczhyt.common.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.sczhyt.modules.sys.entity.SysUserRoleEntity;
import cn.sczhyt.modules.sys.service.SysUserRoleService;
import cn.sczhyt.common.utils.R;



/**
 * 用户与角色对应关系
 *
 * @author luojialin
 * @email 78357966@qq.com
 * @date 2020-06-02 14:07:44
 */
@Api(tags = "用户与角色对应关系")
@RestController
@RequestMapping("sys/userrole")
public class SysUserRoleController extends AbstractController{
    @Autowired
    private SysUserRoleService sysUserRoleService;
    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/info/{id}")
    @RequiresPermissions("sys:userrole:info")
    public R info(@PathVariable("id") String id){
        SysUserRoleEntity sysUserRole = sysUserRoleService.getById(id);

        return R.ok().put("data", sysUserRole);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    @RequiresPermissions("sys:userrole:save")
    public R save(@RequestBody SysUserRoleEntity sysUserRole){
        sysUserRoleService.save(sysUserRole);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    @RequiresPermissions("sys:userrole:update")
    public R update(@RequestBody SysUserRoleEntity sysUserRole){
        ValidatorUtils.validateEntity(sysUserRole);
        sysUserRoleService.updateById(sysUserRole);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    @RequiresPermissions("sys:userrole:delete")
    public R delete(@RequestBody String[] ids){
        sysUserRoleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
